package com.chengfei.thread.demo1;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * 带返回值的线程
 *
 * @author chengfei5
 * @date 2019/1/7
 */
public class NewThread4 implements Callable<Integer> {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        NewThread4 newThread4 = new NewThread4();

        FutureTask<Integer> futureTask = new FutureTask<>(newThread4);
        Thread t = new Thread(futureTask);
        t.start();
        System.out.println("线程执行的结果为："+futureTask.get());
    }

    /**
     * 类似于run方法
     *
     * @return
     * @throws Exception
     */
    @Override
    public Integer call() throws Exception {
        System.out.println("正在进行紧张的计算");
        Thread.sleep(3000);
        return 1;
    }
}
